package job;

import java.io.File;
import java.io.IOException;
import java.util.List;

import models.DrCaseTempExample;
import models.mapper.DrCaseMapper;
import models.mapper.DrCaseTempMapper;

import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.aton.db.SessionFactory;

import controllers.BaseController;
import play.jobs.Job;
import play.jobs.On;
import utils.BizConstants;

/**
 * 清理临时案件任务
 * @author wangshaoming
 *
 */
@On("0 0 2 * * ? * ")
public class ClearCaseTempJob extends Job {
	public static final Logger log=LoggerFactory.getLogger(ClearCaseTempJob.class);
	@Override
	public void doJob(){
		log.info("清理缓存任务开始");
		//清除临时案件
		SqlSession ss = SessionFactory.INSTANCE.getSqlSessionWithoutAutoCommit();
		try{
			DrCaseTempMapper caseMapper=ss.getMapper(DrCaseTempMapper.class);
			DrCaseTempExample example=new DrCaseTempExample();
			caseMapper.deleteByExample(example);
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			ss.close();
		}
		//清除语音合成文件
		File file=new File(BizConstants.FILE_TEMP_PATH);
		if(file.exists()){
			File[] files=file.listFiles();
			for(File child : files){
				child.delete();
			}
		}
		log.info("清理缓存任务结束");
	}
}
